package com.amikomgamedev.panjatpinang;

import java.util.Timer;
import java.util.TimerTask;

/*
 * AndEngineGamePanjatPinang
 * CoolDownButton.java
 * Pratama Wijaya
 * set.mnemonix@gmail.com
 * 9:02:18 PM , Jul 28, 2012
 */

public class CoolDownButton {
	private boolean					valid;
	private Timer					timer;
	private long					delay		= 300;
	private long					nodelay		= 400;
	private static CoolDownButton	instance	= null;

	public static CoolDownButton getSharedInstance() {
		if (instance == null) {
			instance = new CoolDownButton();
		}
		return instance;
	}

	private CoolDownButton() {
		timer = new Timer();
		valid = true;
	}

	public boolean checkValidity() {
		if (valid) {
			valid = false;
			timer.schedule(new Task(), delay);
			return true;
		}
		return false;
	}

	public boolean checkValidityNoDelay() {
		if (valid) {
			valid = false;
			timer.schedule(new Task2(), nodelay);
			return true;
		}
		return false;
	}

	class Task extends TimerTask {
		public void run() {
			valid = true;
		}
	}

	class Task2 extends TimerTask {
		public void run() {
			valid = true;
		}
	}

}
